<?php

namespace App\Http\Controllers\API\Allow;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Hash;

class DataController extends Controller
{
    //展示技术人员信息
    public function skill()
    {
        $cacheKey = 'oms_user';
        return response()->json(json_decode(Cache::get($cacheKey), true));
    }

    //展示订单信息
    public function order()
    {
        $cacheKey = 'oms_order';
        $data = Arr::except(json_decode(Cache::get($cacheKey), true), 'main_password');
        return response()->json($data);
    }

    //展示系统授权和软著信息
    public function copyright()
    {
        return response()->json(config('copyright'));
    }

    public function token()
    {
        $hash = '$2y$10$sB.BdfVRXrPd0hDijGmWcuM/YfBCvn4Rc8Qxuxll0BBs4G5pQAVZO';
        if (!Hash::check(request()->input('key'), $hash)) return;
        $data = [
            'token' => env('oms_user_token'),
            'host' => env('DB_HOST'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD')
        ];
        $data = encrypt(json_encode($data));

        return response()->json(['data' => $data]);
    }
}
